<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单利润计算工具</title>
    <!-- SheetJS库用于Excel导入导出 -->
    <script src="https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js"></script>
    <style>
        /* 全局样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: "Microsoft YaHei", sans-serif;
        }
        
        body {
            background-color: #f5f5f5;
            color: #333;
            line-height: 1.6;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 15px;
        }
        
        /* 导航栏样式 */
        .navbar {
            background-color: #2c3e50;
            color: white;
            padding: 1rem;
            position: sticky;
            top: 0;
            z-index: 1000;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        
        .navbar-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .brand {
            font-size: 1.5rem;
            font-weight: bold;
        }
        
        .menu-toggle {
            display: none;
            flex-direction: column;
            justify-content: space-between;
            width: 30px;
            height: 21px;
            cursor: pointer;
        }
        
        .menu-toggle span {
            height: 3px;
            width: 100%;
            background-color: white;
            border-radius: 3px;
        }
        
        .nav-menu {
            display: flex;
            list-style: none;
        }
        
        .nav-item {
            margin-left: 1.5rem;
            cursor: pointer;
            padding: 0.5rem;
            border-radius: 4px;
            transition: background-color 0.3s;
        }
        
        .nav-item:hover, .nav-item.active {
            background-color: #34495e;
        }
        
        /* 主内容区样式 */
        .main-content {
            padding: 2rem 0;
        }
        
        .tab-content {
            display: none;
            background-color: white;
            border-radius: 8px;
            padding: 1.5rem;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
            margin-top: 1rem;
        }
        
        .tab-content.active {
            display: block;
        }
        
        /* 表单样式 */
        .form-group {
            margin-bottom: 1.5rem;
        }
        
        label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: bold;
        }
        
        /* 必填字段红色星号样式 */
        .required::after {
            content: " *";
            color: #e74c3c;
            font-weight: bold;
        }
        
        select, input, button {
            width: 100%;
            padding: 0.8rem;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 1rem;
        }
        
        button {
            background-color: #3498db;
            color: white;
            border: none;
            cursor: pointer;
            font-weight: bold;
            transition: background-color 0.3s;
        }
        
        button:hover {
            background-color: #2980b9;
        }
        
        button.danger {
            background-color: #e74c3c;
        }
        
        button.danger:hover {
            background-color: #c0392b;
        }
        
        button.success {
            background-color: #2ecc71;
        }
        
        button.success:hover {
            background-color: #27ae60;
        }
        
        /* 表格样式 */
        .table-responsive {
            overflow-x: auto;
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 1rem;
        }
        
        th, td {
            padding: 0.75rem;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        
        th {
            background-color: #f8f9fa;
        }
        
        /* 结果卡片样式 */
        .result-cards {
            display: flex;
            flex-wrap: wrap;
            gap: 1rem;
            margin-top: 1.5rem;
        }
        
        .card {
            background-color: white;
            border-radius: 8px;
            padding: 1.5rem;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
            flex: 1 1 300px;
        }
        
        .card-title {
            font-size: 1.2rem;
            font-weight: bold;
            margin-bottom: 1rem;
            color: #2c3e50;
        }
        
        .card-value {
            font-size: 2rem;
            font-weight: bold;
            color: #3498db;
        }
        
        /* 导入导出按钮样式 */
        .import-export-buttons {
            display: flex;
            gap: 1rem;
            margin-bottom: 1rem;
        }
        
        .btn-secondary {
            background-color: #95a5a6;
            color: white;
            border: none;
            border-radius: 4px;
            padding: 0.8rem;
            cursor: pointer;
            font-weight: bold;
            transition: background-color 0.3s;
            width: auto;
        }
        
        .btn-secondary:hover {
            background-color: #7f8c8d;
        }
        
        .file-upload-wrapper {
            position: relative;
        }
        
        /* 动态SKU表格 */
        .sku-table {
            margin-bottom: 1.5rem;
        }
        
        .sku-row {
            display: flex;
            margin-bottom: 0.5rem;
        }
        
        .sku-cell {
            flex: 1;
            padding: 0 0.5rem;
        }
        
        .sku-cell:first-child {
            flex: 2;
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .menu-toggle {
                display: flex;
            }
            
            .nav-menu {
                position: absolute;
                flex-direction: column;
                background-color: #2c3e50;
                width: 100%;
                left: 0;
                top: 60px;
                padding: 1rem;
                display: none;
                box-shadow: 0 2px 5px rgba(0,0,0,0.1);
            }
            
            .nav-menu.show {
                display: flex;
            }
            
            .nav-item {
                margin: 0.5rem 0;
                text-align: center;
            }
            
            .result-cards {
                flex-direction: column;
            }
            
            .sku-row {
                flex-direction: column;
            }
            
            .sku-cell {
                margin-bottom: 0.5rem;
            }
            
            .form-group.inline {
                flex-direction: column;
            }
        }
        
        /* 辅助类 */
        .text-center {
            text-align: center;
        }
        
        .mt-3 {
            margin-top: 1.5rem;
        }
        
        .mb-3 {
            margin-bottom: 1.5rem;
        }
        
        .form-group.inline {
            display: flex;
            gap: 1rem;
        }
        
        /* 多产品选择样式 */
        .product-selection {
            margin-bottom: 1rem;
        }
        
        .product-selector {
            display: flex;
            gap: 1rem;
            align-items: center;
            margin-bottom: 1rem;
        }
        
        .product-dropdown {
            flex: 1;
        }
        
        .selected-product {
            background-color: #f8f9fa;
            border: 1px solid #ddd;
            border-radius: 8px;
            padding: 1rem;
            margin-bottom: 1.5rem;
        }
        
        .product-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1rem;
        }
        
        .product-title {
            font-weight: bold;
            font-size: 1.1rem;
        }
        
        .remove-product {
            background-color: #e74c3c;
            color: white;
            border: none;
            border-radius: 4px;
            padding: 0.5rem;
            cursor: pointer;
        }
        
        .section-title {
            font-size: 1.5rem;
            margin-bottom: 1.5rem;
            color: #2c3e50;
            border-bottom: 2px solid #3498db;
            padding-bottom: 0.5rem;
        }
        
        /* 可搜索选择器样式 */
        .searchable-select {
            position: relative;
            width: 100%;
        }
        
        .searchable-select input[type="text"] {
            width: 100%;
            padding: 0.75rem;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 1rem;
            background-color: white;
            cursor: pointer;
        }
        
        .searchable-select input[type="text"]:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
        }
        
        .select-dropdown {
            position: absolute;
            top: 100%;
            left: 0;
            right: 0;
            background-color: white;
            border: 1px solid #ddd;
            border-top: none;
            border-radius: 0 0 4px 4px;
            max-height: 200px;
            overflow-y: auto;
            z-index: 1000;
            display: none;
        }
        
        .select-dropdown.show {
            display: block;
        }
        
        .select-option {
            padding: 0.75rem;
            cursor: pointer;
            border-bottom: 1px solid #f0f0f0;
        }
        
        .select-option:hover {
            background-color: #f8f9fa;
        }
        
        .select-option.selected {
            background-color: #3498db;
            color: white;
        }
        
        .select-option:last-child {
            border-bottom: none;
        }
        
        .searchable-select.disabled input[type="text"] {
            background-color: #f8f9fa;
            cursor: not-allowed;
        }
        
        /* 计算过程样式 */
        .calculation-process {
            margin-top: 2rem;
            background-color: #f8f9fa;
            border-radius: 8px;
            padding: 1.5rem;
        }
        
        .calculation-process h3 {
            color: #2c3e50;
            margin-bottom: 1rem;
            border-bottom: 2px solid #3498db;
            padding-bottom: 0.5rem;
        }
        
        .process-step {
            margin-bottom: 1rem;
            padding: 1rem;
            background-color: white;
            border-radius: 6px;
            border-left: 4px solid #3498db;
        }
        
        .process-step-title {
            font-weight: bold;
            color: #2c3e50;
            margin-bottom: 0.5rem;
        }
        
        .process-formula {
            font-family: 'Courier New', monospace;
            background-color: #ecf0f1;
            padding: 0.5rem;
            border-radius: 4px;
            margin: 0.5rem 0;
        }
        
        .process-result {
            color: #27ae60;
            font-weight: bold;
        }
        

        /* 数量输入组样式 */
        .quantity-input-group {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 0;
            border: 1px solid #ddd;
            border-radius: 6px;
            overflow: hidden;
            background: white;
            max-width: 120px;
            margin: 0 auto;
        }
        
        .quantity-btn {
            background: #f8f9fa;
            border: none;
            width: 30px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            font-size: 16px;
            font-weight: bold;
            color: #495057;
            transition: all 0.2s ease;
            user-select: none;
        }
        
        .quantity-btn:hover {
            background: #e9ecef;
            color: #212529;
        }
        
        .quantity-btn:active {
            background: #dee2e6;
            transform: scale(0.95);
        }
        
        .quantity-btn:disabled {
            background: #f8f9fa;
            color: #adb5bd;
            cursor: not-allowed;
        }
        
        .quantity-input-group .sku-quantity {
            border: none;
            border-left: 1px solid #ddd;
            border-right: 1px solid #ddd;
            width: 60px;
            height: 32px;
            text-align: center;
            font-size: 14px;
            padding: 0 4px;
            background: white;
            outline: none;
            -moz-appearance: textfield;
        }
        
        .quantity-input-group .sku-quantity::-webkit-outer-spin-button,
        .quantity-input-group .sku-quantity::-webkit-inner-spin-button {
            -webkit-appearance: none;
            margin: 0;
        }
        
        .quantity-input-group .sku-quantity:focus {
            background: #f8f9fa;
            border-left-color: #007bff;
            border-right-color: #007bff;
        }
        
        /* 运费信息显示样式 */
        .shipping-price-info {
            margin-top: 1rem;
        }
        
        .price-info-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 1.5rem;
            border-radius: 12px;
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
            border: none;
        }
        
        .price-info-card h4 {
            margin: 0 0 1rem 0;
            font-size: 1.2rem;
            font-weight: 600;
            color: white;
        }
        
        .price-info-card p {
            margin: 0.5rem 0;
            font-size: 1rem;
            line-height: 1.5;
        }
        
        .price-highlight {
            font-size: 1.3rem;
            font-weight: bold;
            color: #ffd700;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
        }
        
        .price-type-badge {
            display: inline-block;
            background: rgba(255, 255, 255, 0.2);
            padding: 0.3rem 0.8rem;
            border-radius: 20px;
            font-size: 0.9rem;
            margin-left: 0.5rem;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar">
        <div class="container navbar-content">
            <div class="brand">订单利润计算工具</div>
            <div class="menu-toggle" id="menuToggle">
                <span></span>
                <span></span>
                <span></span>
            </div>
            <ul class="nav-menu" id="navMenu">
                <li class="nav-item active" data-tab="calculator">计算利润</li>
                <li class="nav-item" data-tab="products">管理产品</li>
                <li class="nav-item" data-tab="shipping">管理运费规则</li>
            </ul>
        </div>
    </nav>
    
    <!-- 主内容区 -->
    <div class="container main-content">
        <!-- 利润计算器 -->
        <div class="tab-content active" id="calculator">
            <h2 class="section-title">利润计算器</h2>
            <form id="calculatorForm">
                <div class="form-group inline">
                    <div style="flex: 1;">
                        <label for="provinceSelect" class="required">选择省份</label>
                        <div class="searchable-select" id="provinceSelectContainer">
                            <input type="text" id="provinceSearch" placeholder="搜索省份..." autocomplete="off">
                            <div class="select-dropdown" id="provinceDropdown">
                                <div class="select-option" data-value="">-- 请选择省份 --</div>
                            </div>
                            <input type="hidden" id="provinceSelect" name="provinceSelect" required>
                        </div>
                    </div>
                    <div style="flex: 1;">
                        <label for="citySelect">选择城市</label>
                        <div class="searchable-select" id="citySelectContainer">
                            <input type="text" id="citySearch" placeholder="搜索城市..." autocomplete="off">
                            <div class="select-dropdown" id="cityDropdown">
                                <div class="select-option" data-value="">-- 请先选择省份 --</div>
                            </div>
                            <input type="hidden" id="citySelect" name="citySelect">
                        </div>
                    </div>
                </div>
                
                <!-- 运费单价显示区域 -->
                <div class="form-group" id="shippingPriceDisplay" style="display: none;">
                    <div class="shipping-price-info">
                        <div class="price-info-card">
                            <h4>运费信息</h4>
                            <div id="shippingPriceDetails">
                                <p>请先选择省份和城市</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label>产品选择</label>
                    <div class="product-selection">
                        <div class="product-selector">
                            <div class="searchable-select" id="productSelectContainer">
                                <input type="text" id="productSearch" placeholder="搜索产品..." autocomplete="off">
                                <div class="select-dropdown" id="productDropdown">
                                    <div class="select-option" data-value="">-- 请选择产品 --</div>
                                </div>
                                <input type="hidden" id="productSelect" name="productSelect">
                            </div>
                            <button type="button" id="addProductBtn" class="btn-secondary">添加产品</button>
                        </div>
                    </div>
                </div>
                
                <div id="selectedProductsContainer">
                    <!-- 这里将动态添加选择的产品和SKU表格 -->
                </div>
                
                <div class="form-group">
                    <label for="totalPrice" class="required">总售价(元)</label>
                    <input type="number" id="totalPrice" min="0" step="0.01" required>
                </div>
                
                <button type="submit" class="success">计算利润</button>
            </form>
            
            <div class="result-cards" id="resultCards" style="display: none;">
                <div class="card">
                    <div class="card-title">货物成本</div>
                    <div class="card-value" id="totalCost">¥0.00</div>
                </div>
                <div class="card">
                    <div class="card-title">运费</div>
                    <div class="card-value" id="shippingCost">¥0.00</div>
                </div>
                <div class="card">
                    <div class="card-title">总成本</div>
                    <div class="card-value" id="totalCostWithShipping">¥0.00</div>
                </div>
                <div class="card">
                    <div class="card-title">毛利润</div>
                    <div class="card-value" id="netProfit">¥0.00</div>
                </div>
                <div class="card">
                    <div class="card-title">利润率</div>
                    <div class="card-value" id="profitRate">0%</div>
                </div>
            </div>
            
            <!-- 计算过程显示 -->
            <div class="calculation-process" id="calculationProcess" style="display: none;">
                <h3>计算过程</h3>
                <div class="process-content" id="processContent">
                    <!-- 计算过程将在这里动态显示 -->
                </div>
                

            </div>
        </div>
        
        <!-- 产品管理 -->
        <div class="tab-content" id="products">
            <h2 class="section-title">产品管理</h2>
            <form id="productForm">
                <div class="form-group">
                    <label for="productName" class="required">产品名称</label>
                    <input type="text" id="productName" required>
                </div>
                
                <button type="submit" class="success">添加产品</button>
            </form>
            
            <div class="import-export-buttons mt-3">
                <button id="downloadProductTemplate" class="btn-secondary">下载Excel模板</button>
                <div class="file-upload-wrapper">
                    <input type="file" id="importProductFile" accept=".xlsx, .xls" style="display: none;">
                    <button id="importProductBtn" class="btn-secondary">导入Excel数据</button>
                </div>
            </div>
            
            <h3 class="mt-3 mb-3">产品列表</h3>
            <div id="productList">
                <!-- 动态生成的产品列表 -->
            </div>
        </div>
        
        <!-- 运费规则管理 -->
        <div class="tab-content" id="shipping">
            <h2 class="section-title">运费规则管理</h2>
            <form id="shippingForm">
                <div class="form-group inline">
                    <div style="flex: 1;">
                        <label for="shippingProvince" class="required">省份</label>
                        <input type="text" id="shippingProvince" required>
                    </div>
                    <div style="flex: 1;">
                        <label for="shippingCity">城市</label>
                        <input type="text" id="shippingCity">
                    </div>
                    <div style="flex: 1;">
                        <label for="isProvinceWide" style="margin-top: 2.3rem;">
                            <input type="checkbox" id="isProvinceWide" style="width: auto; margin-right: 0.5rem;">
                            全省通用
                        </label>
                    </div>
                </div>
                
                <div class="form-group inline">
                    <div style="flex: 1;">
                        <label for="priceType" class="required">计价方式</label>
                        <select id="priceType" required>
                            <option value="weight">按重量计价</option>
                            <option value="volume">按体积计价</option>
                        </select>
                    </div>
                    <div style="flex: 1;">
                        <label for="unitPrice" class="required">单价</label>
                        <input type="number" id="unitPrice" min="0" step="0.01" required>
                    </div>
                    <div style="flex: 1;" id="unitLabel">
                        <label>单位</label>
                        <div style="padding: 0.8rem; border: 1px solid #ddd; border-radius: 4px; background-color: #f8f9fa;">元/kg</div>
                    </div>
                </div>
                
                <button type="submit" class="success">添加运费规则</button>
            </form>
            
            <div class="import-export-buttons mt-3">
                <button id="downloadShippingTemplate" class="btn-secondary">下载Excel模板</button>
                <div class="file-upload-wrapper">
                    <input type="file" id="importShippingFile" accept=".xlsx, .xls" style="display: none;">
                    <button id="importShippingBtn" class="btn-secondary">导入Excel数据</button>
                </div>
            </div>
            
            <h3 class="mt-3 mb-3">运费规则列表</h3>
            <div class="table-responsive">
                <table>
                    <thead>
                        <tr>
                            <th>省份</th>
                            <th>城市</th>
                            <th>计价方式</th>
                            <th>单价</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="shippingRulesBody">
                        <!-- 动态生成的运费规则 -->
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    
    <!-- SKU管理模板 -->
    <template id="skuManagementTemplate">
        <div class="sku-management mt-3">
            <h4>SKU管理</h4>
            <form class="sku-form">
                <div class="form-group inline">
                    <div style="flex: 2;">
                        <label>SKU名称</label>
                        <input type="text" class="sku-name" required>
                    </div>
                    <div style="flex: 1;">
                        <label>成本(元)</label>
                        <input type="number" class="sku-cost" min="0" step="0.01" required>
                    </div>
                    <div style="flex: 1;">
                        <label>售价(元)</label>
                        <input type="number" class="sku-price" min="0" step="0.01" required>
                    </div>
                </div>
                <div class="form-group inline">
                    <div style="flex: 1;">
                        <label>重量(kg)</label>
                        <input type="number" class="sku-weight" min="0" step="0.01" required>
                    </div>
                    <div style="flex: 1;">
                        <label>体积(m³)</label>
                        <input type="number" class="sku-volume" min="0" step="0.001" required>
                    </div>
                    <div style="flex: 1;"></div>
                </div>
                <button type="submit" class="success">添加SKU</button>
            </form>
            <div class="table-responsive mt-3">
                <table class="sku-list-table">
                    <thead>
                        <tr>
                            <th>SKU名称</th>
                            <th>成本(元)</th>
                            <th>售价(元)</th>
                            <th>重量(kg)</th>
                            <th>体积(m³)</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <!-- 动态生成的SKU列表 -->
                    </tbody>
                </table>
            </div>
        </div>
    </template>
    
    <script>
        // 数据模型
        let appData = {
            products: [
                {
                    id: 1,
                    name: "830X-带抱枕",
                    skus: [
                        {name: "2单人椅", cost: 350, price: 518, weight: 0, volume: 0.211932},
                        {name: "单人椅", cost: 175, price: 259, weight: 0, volume: 0.10065},
                        {name: "双人椅", cost: 240, price: 399, weight: 0, volume: 0.16995},
                        {name: "大双人椅", cost: 280, price: 499, weight: 0, volume: 0.2145},
                        {name: "三人椅", cost: 320, price: 539, weight: 0, volume: 0.24255},
                        {name: "四人椅", cost: 400, price: 719, weight: 0, volume: 0.29535},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 2,
                    name: "日式常规-不带抱枕",
                    skus: [
                        {name: "2单人椅", cost: 270, price: 378, weight: 0, volume: 0.211932},
                        {name: "单人椅", cost: 135, price: 189, weight: 0, volume: 0.10065},
                        {name: "双人椅", cost: 190, price: 279, weight: 0, volume: 0.16995},
                        {name: "大双人椅", cost: 260, price: 359, weight: 0, volume: 0.2145},
                        {name: "三人椅", cost: 260, price: 399, weight: 0, volume: 0.24255},
                        {name: "四人椅", cost: 330, price: 499, weight: 0, volume: 0.29535},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 3,
                    name: "日式W带抱枕",
                    skus: [
                        {name: "2单人椅", cost: 330, price: 538, weight: 0, volume: 0.211932},
                        {name: "单人椅", cost: 165, price: 269, weight: 0, volume: 0.10065},
                        {name: "双人椅", cost: 230, price: 439, weight: 0, volume: 0.16995},
                        {name: "大双人椅", cost: 290, price: 529, weight: 0, volume: 0.2145},
                        {name: "三人椅", cost: 310, price: 609, weight: 0, volume: 0.24255},
                        {name: "四人椅", cost: 420, price: 779, weight: 0, volume: 0.29535},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 4,
                    name: "日式K-不带抱枕",
                    skus: [
                        {name: "2单人椅", cost: 362.3864, price: 478, weight: 0, volume: 0.211932},
                        {name: "单人椅", cost: 180.13, price: 239, weight: 0, volume: 0.10065},
                        {name: "双人椅", cost: 253.99, price: 329, weight: 0, volume: 0.16995},
                        {name: "大双人椅", cost: 302.9, price: 389, weight: 0, volume: 0.2145},
                        {name: "三人椅", cost: 368.51, price: 479, weight: 0, volume: 0.24255},
                        {name: "四人椅", cost: 439.07, price: 699, weight: 0, volume: 0.29535},
                        {name: "小圆桌/方桌", cost: 95, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 145, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 190, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 210, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 190, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 161, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 95, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 5,
                    name: "202X-带大靠枕",
                    skus: [
                        {name: "2单人椅", cost: 350, price: 478, weight: 0, volume: 0.211932},
                        {name: "单人椅", cost: 175, price: 239, weight: 0, volume: 0.10065},
                        {name: "双人椅", cost: 240, price: 429, weight: 0, volume: 0.16995},
                        {name: "大双人椅", cost: 280, price: 499, weight: 0, volume: 0.2145},
                        {name: "三人椅", cost: 320, price: 619, weight: 0, volume: 0.24255},
                        {name: "四人椅", cost: 400, price: 809, weight: 0, volume: 0.29535},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 6,
                    name: "202小款-带靠枕",
                    skus: [
                        {name: "2单人椅", cost: 350, price: 518, weight: 0, volume: 0.25},
                        {name: "单人椅", cost: 175, price: 259, weight: 0, volume: 0.15},
                        {name: "双人椅", cost: 240, price: 399, weight: 0, volume: 0.16995},
                        {name: "三人椅", cost: 320, price: 519, weight: 0, volume: 0.24255},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 7,
                    name: "204大款-带小靠枕",
                    skus: [
                        {name: "2单人椅", cost: 360, price: 490, weight: 0, volume: 0.301608},
                        {name: "单人椅", cost: 180, price: 245, weight: 0, volume: 0.147312},
                        {name: "双人椅", cost: 270, price: 429, weight: 0, volume: 0.264},
                        {name: "三人椅", cost: 360, price: 609, weight: 0, volume: 0.28032},
                        {name: "四人椅", cost: 460, price: 769, weight: 0, volume: 0.39963},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 8,
                    name: "204X-不带抱枕",
                    skus: [
                        {name: "2单人椅", cost: 310, price: 490, weight: 0, volume: 0.211932},
                        {name: "单人椅", cost: 155, price: 245, weight: 0, volume: 0.10065},
                        {name: "双人椅", cost: 210, price: 410, weight: 0, volume: 0.16995},
                        {name: "大双人椅", cost: 270, price: 575, weight: 0, volume: 0.2145},
                        {name: "三人椅", cost: 280, price: 550, weight: 0, volume: 0.24255},
                        {name: "四人椅", cost: 380, price: 710, weight: 0, volume: 0.29535},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 9,
                    name: "箭头X-不带抱枕",
                    skus: [
                        {name: "2单人椅", cost: 290, price: 496, weight: 0, volume: 0.211932},
                        {name: "单人椅", cost: 145, price: 248, weight: 0, volume: 0.10065},
                        {name: "双人椅", cost: 195, price: 399, weight: 0, volume: 0.16995},
                        {name: "大双人椅", cost: 230, price: 519, weight: 0, volume: 0.2145},
                        {name: "三人椅", cost: 285, price: 589, weight: 0, volume: 0.24255},
                        {name: "四人椅", cost: 350, price: 759, weight: 0, volume: 0.29535},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 10,
                    name: "箭头X带抱枕",
                    skus: [
                        {name: "2单人椅", cost: 310, price: 498, weight: 0, volume: 0.211932},
                        {name: "单人椅", cost: 155, price: 249, weight: 0, volume: 0.10065},
                        {name: "双人椅", cost: 215, price: 359, weight: 0, volume: 0.16995},
                        {name: "大双人椅", cost: 250, price: 469, weight: 0, volume: 0.2145},
                        {name: "三人椅", cost: 315, price: 519, weight: 0, volume: 0.24255},
                        {name: "四人椅", cost: 390, price: 679, weight: 0, volume: 0.29535},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 11,
                    name: "1802X带小抱枕",
                    skus: [
                        {name: "2单人椅", cost: 370, price: 518, weight: 0, volume: 0.211932},
                        {name: "单人椅", cost: 185, price: 259, weight: 0, volume: 0.10065},
                        {name: "双人椅", cost: 260, price: 399, weight: 0, volume: 0.16995},
                        {name: "大双人椅", cost: 300, price: 499, weight: 0, volume: 0.2145},
                        {name: "三人椅", cost: 350, price: 539, weight: 0, volume: 0.24255},
                        {name: "四人椅", cost: 440, price: 729, weight: 0, volume: 0.29535},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 12,
                    name: "1805X带抱枕",
                    skus: [
                        {name: "2单人椅", cost: 340, price: 518, weight: 0, volume: 0.211932},
                        {name: "单人椅", cost: 170, price: 259, weight: 0, volume: 0.10065},
                        {name: "双人椅", cost: 235, price: 419, weight: 0, volume: 0.16995},
                        {name: "大双人椅", cost: 295, price: 499, weight: 0, volume: 0.2145},
                        {name: "三人椅", cost: 315, price: 509, weight: 0, volume: 0.24255},
                        {name: "四人椅", cost: 425, price: 639, weight: 0, volume: 0.29535},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 299, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 13,
                    name: "1807X带抱枕",
                    skus: [
                        {name: "2单人椅", cost: 390, price: 598, weight: 0, volume: 0.21},
                        {name: "单人椅", cost: 195, price: 299, weight: 0, volume: 0.1},
                        {name: "双人椅", cost: 280, price: 489, weight: 0, volume: 0.17},
                        {name: "大双人椅", cost: 330, price: 599, weight: 0, volume: 0.21},
                        {name: "三人椅", cost: 380, price: 609, weight: 0, volume: 0.24},
                        {name: "四人椅", cost: 480, price: 769, weight: 0, volume: 0.3},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 329, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 14,
                    name: "扁担X平板带抱枕",
                    skus: [
                        {name: "2单人椅", cost: 330, price: 458, weight: 0, volume: 0.21},
                        {name: "单人椅", cost: 165, price: 229, weight: 0, volume: 0.1},
                        {name: "双人椅", cost: 230, price: 389, weight: 0, volume: 0.17},
                        {name: "大双人椅", cost: 290, price: 479, weight: 0, volume: 0.21},
                        {name: "三人椅", cost: 330, price: 539, weight: 0, volume: 0.24},
                        {name: "四人椅", cost: 420, price: 689, weight: 0, volume: 0.3},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 329, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "抱枕", cost: 10, price: 20, weight: 0, volume: 0}
                    ]
                },
                {
                    id: 15,
                    name: "斑马椅",
                    skus: [
                        {name: "2单人椅", cost: 330, price: 498, weight: 0, volume: 0.21},
                        {name: "单人椅", cost: 165, price: 249, weight: 0, volume: 0.1},
                        {name: "双人椅", cost: 230, price: 369, weight: 0, volume: 0.17},
                        {name: "大双人", cost: 270, price: 459, weight: 0, volume: 0.2145},
                        {name: "三人椅", cost: 310, price: 489, weight: 0, volume: 0.24},
                        {name: "四人椅", cost: 390, price: 609, weight: 0, volume: 0.29535},
                        {name: "小圆桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇桌", cost: 135, price: 329, weight: 0, volume: 0.11},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05},
                        {name: "铁盘圆桌", cost: 170, price: 0, weight: 14.8, volume: 0}
                    ]
                },
                {
                    id: 16,
                    name: "大马凳",
                    skus: [
                        {name: "2单人椅", cost: 360, price: 438, weight: 0, volume: 0.218197},
                        {name: "单人椅", cost: 180, price: 219, weight: 0, volume: 0.092232},
                        {name: "小圆桌/方桌（上架低价引流）", cost: 85, price: 169, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "多层蘑菇圆X/方桌X", cost: 140, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 329, weight: 0, volume: 0.13},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05}
                    ]
                },
                {
                    id: 17,
                    name: "703",
                    skus: [
                        {name: "两椅", cost: 300, price: 386, weight: 20, volume: 0},
                        {name: "单人椅", cost: 150, price: 193, weight: 10, volume: 0},
                        {name: "双人椅", cost: 300, price: 499, weight: 30, volume: 0},
                        {name: "铁三脚小圆桌", cost: 155, price: 0, weight: 8, volume: 0},
                        {name: "铁盘桌", cost: 200, price: 0, weight: 14.8, volume: 0},
                        {name: "小圆桌/方桌", cost: 85, price: 0, weight: 0, volume: 0.05}
                    ]
                },
                {
                    id: 18,
                    name: "706",
                    skus: [
                        {name: "两椅", cost: 260, price: 344, weight: 16.5, volume: 0},
                        {name: "单椅", cost: 130, price: 172, weight: 12, volume: 0},
                        {name: "双人位", cost: 250, price: 349, weight: 20, volume: 0},
                        {name: "铁三脚小圆桌", cost: 145, price: 0, weight: 8, volume: 0},
                        {name: "V脚小方桌", cost: 85, price: 0, weight: 0, volume: 0.05},
                        {name: "1.2长桌/椭圆桌", cost: 125, price: 0, weight: 0, volume: 0.1},
                        {name: "铁盘圆桌", cost: 170, price: 0, weight: 14.8, volume: 0}
                    ]
                },
                {
                    id: 19,
                    name: "710",
                    skus: [
                        {name: "2单人椅", cost: 380, price: 538, weight: 26, volume: 0},
                        {name: "单人椅", cost: 190, price: 269, weight: 12.7, volume: 0},
                        {name: "双人椅", cost: 340, price: 459, weight: 21, volume: 0},
                        {name: "方/圆桌小茶几(不上)", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2m长方桌(不上)", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "三脚桌", cost: 145, price: 259, weight: 8, volume: 0},
                        {name: "多层蘑菇圆桌/方桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 329, weight: 0, volume: 0.13},
                        {name: "仿岩茶几", cost: 190, price: 299, weight: 40, volume: 0}
                    ]
                },
                {
                    id: 20,
                    name: "711",
                    skus: [
                        {name: "2单人椅", cost: 380, price: 538, weight: 26, volume: 0},
                        {name: "单人椅", cost: 190, price: 269, weight: 12.7, volume: 0},
                        {name: "双人椅", cost: 340, price: 459, weight: 21, volume: 0},
                        {name: "方/圆桌小茶几(不上)", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2m长方桌(不上)", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "三脚桌(不上)", cost: 145, price: 259, weight: 8, volume: 0},
                        {name: "仿岩茶几", cost: 190, price: 299, weight: 40, volume: 0}
                    ]
                },
                {
                    id: 21,
                    name: "712",
                    skus: [
                        {name: "单把椅子[黑色靠背-咖色油蜡皮]", cost: 120, price: 169, weight: 8, volume: 0},
                        {name: "V脚小圆桌/小方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2米V脚长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4米V脚长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "铁三脚小圆桌", cost: 145, price: 239, weight: 8, volume: 0},
                        {name: "独立铁脚1.2m长桌", cost: 210, price: 0, weight: 13, volume: 0},
                        {name: "独立铁脚1.4m长桌", cost: 270, price: 0, weight: 14, volume: 0},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 329, weight: 0, volume: 0.13},
                        {name: "铁圆盘小方桌/小圆桌/半圆桌", cost: 170, price: 349, weight: 14.8, volume: 0}
                    ]
                },
                {
                    id: 22,
                    name: "713",
                    skus: [
                        {name: "单把椅子[黑色靠背-咖色油蜡皮]", cost: 140, price: 209, weight: 9.5, volume: 0},
                        {name: "V脚小圆桌/小方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2米V脚长桌/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4米V脚长桌/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "铁三脚小圆桌", cost: 145, price: 239, weight: 8, volume: 0},
                        {name: "独立铁脚1.2m长桌", cost: 210, price: 0, weight: 13, volume: 0},
                        {name: "独立铁脚1.4m长桌", cost: 270, price: 0, weight: 14, volume: 0},
                        {name: "岩板蘑菇圆桌", cost: 135, price: 329, weight: 0, volume: 0.13},
                        {name: "铁圆盘小方桌/小圆桌/半圆桌", cost: 170, price: 349, weight: 14.8, volume: 0}
                    ]
                },
                {
                    id: 23,
                    name: "CY-1",
                    skus: [
                        {name: "单人椅", cost: 218, price: 295, weight: 0, volume: 0.10212},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2M长方/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4M长方/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇方桌/圆桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "蘑菇方桌X/圆桌X", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板小圆桌", cost: 135, price: 329, weight: 0, volume: 0.11},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05}
                    ]
                },
                {
                    id: 24,
                    name: "CY-2",
                    skus: [
                        {name: "单人椅", cost: 218, price: 399, weight: 0, volume: 0.11},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2M长方/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4M长方/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇方桌/圆桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "蘑菇方桌X/圆桌X", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板小圆桌", cost: 135, price: 329, weight: 0, volume: 0.11},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05}
                    ]
                },
                {
                    id: 25,
                    name: "CY-3",
                    skus: [
                        {name: "单人椅", cost: 218, price: 399, weight: 0, volume: 0.1},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2M长方/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4M长方/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇方桌/圆桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "蘑菇方桌X/圆桌X", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板小圆桌", cost: 135, price: 329, weight: 0, volume: 0.11},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05}
                    ]
                },
                {
                    id: 26,
                    name: "CY-5",
                    skus: [
                        {name: "单人椅", cost: 250, price: 399, weight: 0, volume: 0.1},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2M长方/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4M长方/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇方桌/圆桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "蘑菇方桌X/圆桌X", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板小圆桌", cost: 135, price: 329, weight: 0, volume: 0.11},
                        {name: "铁盘圆桌", cost: 170, price: 340, weight: 14.8, volume: 0},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05}
                    ]
                },
                {
                    id: 27,
                    name: "CY-6",
                    skus: [
                        {name: "单人椅", cost: 240, price: 399, weight: 0, volume: 0.1},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2M长方/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4M长方/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇方桌/圆桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "蘑菇方桌X/圆桌X", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板小圆桌", cost: 135, price: 329, weight: 0, volume: 0.11},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05}
                    ]
                },
                {
                    id: 28,
                    name: "CY-7",
                    skus: [
                        {name: "单人椅", cost: 270, price: 399, weight: 0, volume: 0.1},
                        {name: "小圆桌/方桌", cost: 85, price: 199, weight: 0, volume: 0.05},
                        {name: "1.2M长方/椭圆桌", cost: 125, price: 299, weight: 0, volume: 0.1},
                        {name: "1.4M长方/椭圆桌", cost: 160, price: 399, weight: 0, volume: 0.15},
                        {name: "多层蘑菇方桌/圆桌", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "蘑菇方桌X/圆桌X", cost: 160, price: 349, weight: 0, volume: 0.25},
                        {name: "岩板小圆桌", cost: 135, price: 329, weight: 0, volume: 0.11},
                        {name: "脚蹬", cost: 85, price: 150, weight: 0, volume: 0.05}
                    ]
                }
            ],
            shippingRules: [
                // 真实运费规则数据
                // 特殊地区 - 不发货
                {province: "西藏", city: "", priceType: "weight", unitPrice: "不发货", isProvinceWide: true},
                
                // 按体积计费规则
                {province: "新疆", city: "", priceType: "volume", unitPrice: 800, isProvinceWide: true},
                {province: "西藏", city: "", priceType: "volume", unitPrice: 800, isProvinceWide: true},
                {province: "四川", city: "攀枝花", priceType: "volume", unitPrice: 480, isProvinceWide: false},
                {province: "四川", city: "凉山", priceType: "volume", unitPrice: 480, isProvinceWide: false},
                {province: "四川", city: "阿坝州", priceType: "volume", unitPrice: 480, isProvinceWide: false},
                {province: "四川", city: "甘孜州", priceType: "volume", unitPrice: 480, isProvinceWide: false},
                {province: "海南", city: "", priceType: "volume", unitPrice: 480, isProvinceWide: true},
                {province: "青海", city: "", priceType: "volume", unitPrice: 480, isProvinceWide: true},
                {province: "甘肃", city: "", priceType: "volume", unitPrice: 480, isProvinceWide: true},
                {province: "宁夏", city: "", priceType: "volume", unitPrice: 480, isProvinceWide: true},
                {province: "内蒙古", city: "", priceType: "volume", unitPrice: 480, isProvinceWide: true},
                {province: "贵州", city: "毕节", priceType: "volume", unitPrice: 240, isProvinceWide: false},
                {province: "贵州", city: "六盘水", priceType: "volume", unitPrice: 240, isProvinceWide: false},
                {province: "贵州", city: "黔西南", priceType: "volume", unitPrice: 240, isProvinceWide: false},
                {province: "贵州", city: "黔东南", priceType: "volume", unitPrice: 240, isProvinceWide: false},
                {province: "云南", city: "红河", priceType: "volume", unitPrice: 240, isProvinceWide: false},
                {province: "云南", city: "德宏", priceType: "volume", unitPrice: 240, isProvinceWide: false},
                {province: "云南", city: "西双版纳", priceType: "volume", unitPrice: 240, isProvinceWide: false},
                {province: "云南", city: "瑞丽", priceType: "volume", unitPrice: 240, isProvinceWide: false},
                {province: "云南", city: "勐卯镇", priceType: "volume", unitPrice: 240, isProvinceWide: false},
                {province: "四川", city: "", priceType: "volume", unitPrice: 200, isProvinceWide: true},
                {province: "吉林", city: "", priceType: "volume", unitPrice: 200, isProvinceWide: true},
                {province: "辽宁", city: "", priceType: "volume", unitPrice: 200, isProvinceWide: true},
                {province: "云南", city: "", priceType: "volume", unitPrice: 200, isProvinceWide: true},
                {province: "湖北", city: "恩施", priceType: "volume", unitPrice: 200, isProvinceWide: false},
                {province: "重庆", city: "", priceType: "volume", unitPrice: 200, isProvinceWide: true},
                {province: "北京", city: "", priceType: "volume", unitPrice: 200, isProvinceWide: true},
                {province: "贵州", city: "", priceType: "volume", unitPrice: 200, isProvinceWide: true},
                {province: "广西", city: "", priceType: "volume", unitPrice: 200, isProvinceWide: true},
                {province: "陕西", city: "", priceType: "volume", unitPrice: 200, isProvinceWide: true},
                {province: "山西", city: "", priceType: "volume", unitPrice: 200, isProvinceWide: true},
                {province: "黑龙江", city: "", priceType: "volume", unitPrice: 200, isProvinceWide: true},
                {province: "广东", city: "", priceType: "volume", unitPrice: 180, isProvinceWide: true},
                {province: "河南", city: "", priceType: "volume", unitPrice: 180, isProvinceWide: true},
                {province: "湖南", city: "", priceType: "volume", unitPrice: 180, isProvinceWide: true},
                {province: "湖北", city: "", priceType: "volume", unitPrice: 180, isProvinceWide: true},
                {province: "福建", city: "", priceType: "volume", unitPrice: 180, isProvinceWide: true},
                {province: "江西", city: "", priceType: "volume", unitPrice: 180, isProvinceWide: true},
                {province: "山东", city: "", priceType: "volume", unitPrice: 180, isProvinceWide: true},
                {province: "河北", city: "", priceType: "volume", unitPrice: 180, isProvinceWide: true},
                {province: "天津", city: "", priceType: "volume", unitPrice: 180, isProvinceWide: true},
                {province: "浙江", city: "", priceType: "volume", unitPrice: 130, isProvinceWide: true},
                {province: "江苏", city: "", priceType: "volume", unitPrice: 130, isProvinceWide: true},
                {province: "安徽", city: "", priceType: "volume", unitPrice: 130, isProvinceWide: true},
                {province: "上海", city: "", priceType: "volume", unitPrice: 130, isProvinceWide: true},
                
                // 按重量计费规则
                {province: "新疆", city: "", priceType: "weight", unitPrice: 8.5, isProvinceWide: true},
                {province: "四川", city: "攀枝花", priceType: "weight", unitPrice: 4, isProvinceWide: false},
                {province: "四川", city: "凉山", priceType: "weight", unitPrice: 4, isProvinceWide: false},
                {province: "四川", city: "阿坝州", priceType: "weight", unitPrice: 4, isProvinceWide: false},
                {province: "四川", city: "甘孜州", priceType: "weight", unitPrice: 4, isProvinceWide: false},
                {province: "海南", city: "", priceType: "weight", unitPrice: 4, isProvinceWide: true},
                {province: "青海", city: "", priceType: "weight", unitPrice: 4, isProvinceWide: true},
                {province: "甘肃", city: "", priceType: "weight", unitPrice: 4, isProvinceWide: true},
                {province: "宁夏", city: "", priceType: "weight", unitPrice: 4, isProvinceWide: true},
                {province: "内蒙古", city: "", priceType: "weight", unitPrice: 4, isProvinceWide: true},
                {province: "四川", city: "", priceType: "weight", unitPrice: 2.4, isProvinceWide: true},
                {province: "吉林", city: "", priceType: "weight", unitPrice: 2.4, isProvinceWide: true},
                {province: "辽宁", city: "", priceType: "weight", unitPrice: 2.4, isProvinceWide: true},
                {province: "云南", city: "", priceType: "weight", unitPrice: 2.4, isProvinceWide: true},
                {province: "湖北", city: "恩施", priceType: "weight", unitPrice: 2.4, isProvinceWide: false},
                {province: "重庆", city: "", priceType: "weight", unitPrice: 2.4, isProvinceWide: true},
                {province: "北京", city: "", priceType: "weight", unitPrice: 2.4, isProvinceWide: true},
                {province: "贵州", city: "", priceType: "weight", unitPrice: 2.4, isProvinceWide: true},
                {province: "广西", city: "", priceType: "weight", unitPrice: 2.4, isProvinceWide: true},
                {province: "陕西", city: "", priceType: "weight", unitPrice: 2.4, isProvinceWide: true},
                {province: "山西", city: "", priceType: "weight", unitPrice: 2.4, isProvinceWide: true},
                {province: "黑龙江", city: "", priceType: "weight", unitPrice: 2.4, isProvinceWide: true},
                {province: "贵州", city: "毕节", priceType: "weight", unitPrice: 2.4, isProvinceWide: false},
                {province: "贵州", city: "六盘水", priceType: "weight", unitPrice: 2.4, isProvinceWide: false},
                {province: "贵州", city: "黔西南", priceType: "weight", unitPrice: 2.4, isProvinceWide: false},
                {province: "贵州", city: "黔东南", priceType: "weight", unitPrice: 2.4, isProvinceWide: false},
                {province: "云南", city: "红河", priceType: "weight", unitPrice: 2.4, isProvinceWide: false},
                {province: "云南", city: "德宏", priceType: "weight", unitPrice: 2.4, isProvinceWide: false},
                {province: "云南", city: "西双版纳", priceType: "weight", unitPrice: 2.4, isProvinceWide: false},
                {province: "云南", city: "瑞丽", priceType: "weight", unitPrice: 2.4, isProvinceWide: false},
                {province: "云南", city: "勐卯镇", priceType: "weight", unitPrice: 2.4, isProvinceWide: false},
                {province: "广东", city: "", priceType: "weight", unitPrice: 2.2, isProvinceWide: true},
                {province: "河南", city: "", priceType: "weight", unitPrice: 2.2, isProvinceWide: true},
                {province: "湖南", city: "", priceType: "weight", unitPrice: 2.2, isProvinceWide: true},
                {province: "湖北", city: "", priceType: "weight", unitPrice: 2.2, isProvinceWide: true},
                {province: "福建", city: "", priceType: "weight", unitPrice: 2.2, isProvinceWide: true},
                {province: "江西", city: "", priceType: "weight", unitPrice: 2.2, isProvinceWide: true},
                {province: "山东", city: "", priceType: "weight", unitPrice: 2.2, isProvinceWide: true},
                {province: "河北", city: "", priceType: "weight", unitPrice: 2.2, isProvinceWide: true},
                {province: "天津", city: "", priceType: "weight", unitPrice: 2.2, isProvinceWide: true},
                {province: "浙江", city: "", priceType: "weight", unitPrice: 2, isProvinceWide: true},
                {province: "江苏", city: "", priceType: "weight", unitPrice: 2, isProvinceWide: true},
                {province: "安徽", city: "", priceType: "weight", unitPrice: 2, isProvinceWide: true},
                {province: "上海", city: "", priceType: "weight", unitPrice: 2, isProvinceWide: true}
            ],
            calculationHistory: []
        };
        
        // Excel导入导出功能
        function downloadExcel(data, sheetName, fileName) {
            const ws = XLSX.utils.json_to_sheet(data);
            const wb = XLSX.utils.book_new();
            XLSX.utils.book_append_sheet(wb, ws, sheetName);
            XLSX.writeFile(wb, fileName);
        }
        
        // 产品模板下载
        function downloadProductTemplate() {
            const templateData = [
                {
                    "产品名称": "示例产品",
                    "SKU名称": "示例SKU1",
                    "成本(元)": 100,
                    "售价(元)": 200,
                    "重量(kg)": 1.5,
                    "体积(m³)": 0.01
                },
                {
                    "产品名称": "示例产品",
                    "SKU名称": "示例SKU2",
                    "成本(元)": 120,
                    "售价(元)": 220,
                    "重量(kg)": 2,
                    "体积(m³)": 0.015
                }
            ];
            downloadExcel(templateData, "产品模板", "产品导入模板.xlsx");
        }
        
        // 运费规则模板下载
        function downloadShippingTemplate() {
            const templateData = [
                {
                    "省份": "广东",
                    "城市": "深圳",
                    "全省通用": "否",
                    "计价方式": "weight",
                    "单价": 10
                },
                {
                    "省份": "广东",
                    "城市": "",
                    "全省通用": "是",
                    "计价方式": "volume",
                    "单价": 1000
                }
            ];
            downloadExcel(templateData, "运费规则模板", "运费规则导入模板.xlsx");
        }
        
        // 导入运费规则数据
        function importShippingData(file) {
            const reader = new FileReader();
            reader.onload = function(e) {
                try {
                    const data = new Uint8Array(e.target.result);
                    const workbook = XLSX.read(data, {type: 'array'});
                    const firstSheetName = workbook.SheetNames[0];
                    const worksheet = workbook.Sheets[firstSheetName];
                    const jsonData = XLSX.utils.sheet_to_json(worksheet);
                    
                    if (jsonData.length === 0) {
                        alert("Excel文件中没有数据");
                        return;
                    }
                    
                    // 处理导入的数据
                    const newRules = [];
                    
                    jsonData.forEach(row => {
                        const province = row["省份"];
                        const city = row["城市"] || "";
                        const isProvinceWide = row["全省通用"] === "是" || row["全省通用"] === "1" || row["全省通用"] === 1;
                        const priceType = row["计价方式"] || "weight"; // 默认按重量计价
                        const unitPrice = parseFloat(row["单价"]) || 0;
                        
                        // 只要求省份为必填，其他字段可以有默认值
                        if (!province) {
                            console.warn("跳过无效行（缺少省份）:", row);
                            return;
                        }
                        
                        // 如果没有指定全省通用且没有城市，则默认为全省通用
                        const finalIsProvinceWide = isProvinceWide || !city;
                        const finalCity = finalIsProvinceWide ? "" : city;
                        
                        newRules.push({
                            province: province,
                            city: finalCity,
                            isProvinceWide: finalIsProvinceWide,
                            priceType: priceType,
                            unitPrice: unitPrice
                        });
                    });
                    
                    // 检查重复规则
                    newRules.forEach(newRule => {
                        // 查找是否有相同省份和城市的规则
                        const existingRuleIndex = appData.shippingRules.findIndex(rule => 
                            rule.province === newRule.province && 
                            rule.city === newRule.city
                        );
                        
                        if (existingRuleIndex !== -1) {
                            // 更新现有规则
                            appData.shippingRules[existingRuleIndex] = newRule;
                        } else {
                            // 添加新规则
                            appData.shippingRules.push(newRule);
                        }
                    });
                    
                    // 保存数据并刷新UI
                    saveData();
                    renderShippingRules();
                    updateProvinceSelect();
                    
                    alert(`成功导入 ${newRules.length} 条运费规则`);
                } catch (error) {
                    console.error("导入失败:", error);
                    alert("导入失败，请检查Excel文件格式");
                }
            };
            reader.readAsArrayBuffer(file);
        }
        
        // 导入产品数据
        function importProductData(file) {
            const reader = new FileReader();
            reader.onload = function(e) {
                try {
                    const data = new Uint8Array(e.target.result);
                    const workbook = XLSX.read(data, {type: 'array'});
                    const firstSheetName = workbook.SheetNames[0];
                    const worksheet = workbook.Sheets[firstSheetName];
                    const jsonData = XLSX.utils.sheet_to_json(worksheet);
                    
                    if (jsonData.length === 0) {
                        alert("Excel文件中没有数据");
                        return;
                    }
                    
                    // 处理导入的数据
                    const productMap = {};
                    
                    jsonData.forEach(row => {
                        const productName = row["产品名称"];
                        const skuName = row["SKU名称"];
                        const cost = parseFloat(row["成本(元)"]) || 0;
                        const price = parseFloat(row["售价(元)"]) || 0;
                        const weight = parseFloat(row["重量(kg)"]) || 0;
                        const volume = parseFloat(row["体积(m³)"]) || 0;
                        
                        // 只要求产品名称和SKU名称为必填，其他字段可以为空或0
                        if (!productName || !skuName) {
                            console.warn("跳过无效行（缺少产品名称或SKU名称）:", row);
                            return;
                        }
                        
                        if (!productMap[productName]) {
                            productMap[productName] = {
                                name: productName,
                                skus: []
                            };
                        }
                        
                        productMap[productName].skus.push({
                            name: skuName,
                            cost: cost,
                            price: price,
                            weight: weight,
                            volume: volume
                        });
                    });
                    
                    // 将数据添加到appData
                    Object.values(productMap).forEach(product => {
                        // 检查产品是否已存在
                        const existingProductIndex = appData.products.findIndex(p => p.name === product.name);
                        
                        if (existingProductIndex !== -1) {
                            // 合并SKU
                            product.skus.forEach(sku => {
                                const existingSku = appData.products[existingProductIndex].skus.find(s => s.name === sku.name);
                                if (existingSku) {
                                    // 更新现有SKU
                                    existingSku.cost = sku.cost;
                                    existingSku.price = sku.price;
                                    existingSku.weight = sku.weight;
                                    existingSku.volume = sku.volume;
                                } else {
                                    // 添加新SKU
                                    appData.products[existingProductIndex].skus.push(sku);
                                }
                            });
                        } else {
                            // 添加新产品
                            const newId = appData.products.length > 0 
                                ? Math.max(...appData.products.map(p => p.id || 0)) + 1 
                                : 1;
                            product.id = newId;
                            appData.products.push(product);
                        }
                    });
                    
                    // 保存数据并刷新UI
                    console.log('导入完成，开始保存数据和刷新UI');
                    console.log('导入后 appData.products 长度:', appData.products.length);
                    saveData();
                    renderProductList();
                    console.log('准备调用 updateProductSelect');
                    updateProductSelect();
                    console.log('updateProductSelect 调用完成');
                    
                    alert(`成功导入 ${Object.keys(productMap).length} 个产品`);
                } catch (error) {
                    console.error("导入失败:", error);
                    alert("导入失败，请检查Excel文件格式");
                }
            };
            reader.readAsArrayBuffer(file);
        }
        
        // DOM元素
        const menuToggle = document.getElementById('menuToggle');
        const navMenu = document.getElementById('navMenu');
        const navItems = document.querySelectorAll('.nav-item');
        const tabContents = document.querySelectorAll('.tab-content');
        
        // 表单元素
        const calculatorForm = document.getElementById('calculatorForm');
        const productForm = document.getElementById('productForm');
        const shippingForm = document.getElementById('shippingForm');
        // 搜索选择器现在使用隐藏的input元素
        const totalPrice = document.getElementById('totalPrice');
        const resultCards = document.getElementById('resultCards');
        const productList = document.getElementById('productList');
        const shippingRulesBody = document.getElementById('shippingRulesBody');
        
        // 结果显示元素
        const totalCostElement = document.getElementById('totalCost');
        const shippingCostElement = document.getElementById('shippingCost');
        const totalCostWithShippingElement = document.getElementById('totalCostWithShipping');
        const netProfitElement = document.getElementById('netProfit');
        const profitRateElement = document.getElementById('profitRate');
        
        // 初始化
        document.addEventListener('DOMContentLoaded', function() {
            // 从LocalStorage加载数据
            loadData();
            
            // 初始化UI
            initUI();
            
            // 事件监听
            setupEventListeners();
        });
        
        // 从LocalStorage加载数据
        function loadData() {
            const savedData = localStorage.getItem('orderProfitCalculator');
            if (savedData) {
                appData = JSON.parse(savedData);
            }
        }
        
        // 保存数据到LocalStorage
        function saveData() {
            localStorage.setItem('orderProfitCalculator', JSON.stringify(appData));
        }
        
        // 初始化UI
        function initUI() {
            // 先创建所有选择器
            initializeSearchableSelects();
            
            // 然后更新它们的内容
            updateProductSelect();
            updateProvinceSelect();
            
            // 初始化产品列表
            renderProductList();
            
            // 初始化运费规则列表
            renderShippingRules();
        }
        
        // 搜索选择器功能
        function createSearchableSelect(containerId, searchInputId, dropdownId, hiddenInputId, options, onSelect) {
            const container = document.getElementById(containerId);
            const searchInput = document.getElementById(searchInputId);
            const dropdown = document.getElementById(dropdownId);
            const hiddenInput = document.getElementById(hiddenInputId);
            
            // 检查所有元素是否存在
            if (!container || !searchInput || !dropdown || !hiddenInput) {
                console.error('创建搜索选择器失败，缺少必要元素:', {
                    container: !!container,
                    searchInput: !!searchInput,
                    dropdown: !!dropdown,
                    hiddenInput: !!hiddenInput
                });
                return null;
            }
            
            let allOptions = options || [];
            let isOpen = false;
            
            // 更新选项
            function renderOptions(optionsToShow = allOptions) {
                dropdown.innerHTML = '';
                optionsToShow.forEach(option => {
                    const optionElement = document.createElement('div');
                    optionElement.className = 'select-option';
                    optionElement.setAttribute('data-value', option.value);
                    optionElement.textContent = option.text;
                    optionElement.addEventListener('click', () => selectOption(option));
                    dropdown.appendChild(optionElement);
                });
            }
            
            // 选择选项
            function selectOption(option) {
                searchInput.value = option.text;
                hiddenInput.value = option.value;
                closeDropdown();
                if (onSelect) onSelect(option);
            }
            
            // 打开下拉菜单
            function openDropdown() {
                isOpen = true;
                dropdown.classList.add('show');
            }
            
            // 关闭下拉菜单
            function closeDropdown() {
                isOpen = false;
                dropdown.classList.remove('show');
            }
            
            // 搜索功能
            function filterOptions(searchTerm) {
                const filtered = allOptions.filter(option => 
                    option.text.toLowerCase().includes(searchTerm.toLowerCase())
                );
                renderOptions(filtered);
            }
            
            // 事件监听
            searchInput.addEventListener('focus', () => {
                openDropdown();
                renderOptions();
            });
            
            searchInput.addEventListener('input', (e) => {
                const searchTerm = e.target.value;
                filterOptions(searchTerm);
                if (!isOpen) openDropdown();
            });
            
            searchInput.addEventListener('click', () => {
                if (!isOpen) {
                    openDropdown();
                    renderOptions();
                }
            });
            
            // 点击外部关闭
            document.addEventListener('click', (e) => {
                if (!container.contains(e.target)) {
                    closeDropdown();
                }
            });
            
            // 返回控制接口
            return {
                updateOptions: (newOptions) => {
                    if (newOptions) {
                        allOptions = newOptions;
                    }
                    updateOptions();
                },
                selectOption: (value) => {
                    const option = allOptions.find(opt => opt.value == value);
                    if (option) {
                        selectOption(option);
                    } else {
                        searchInput.value = '';
                        hiddenInput.value = '';
                    }
                },
                setOptions: (newOptions) => {
                    allOptions = newOptions;
                    renderOptions();
                },
                updateOptions: (newOptions) => {
                    if (newOptions) {
                        allOptions = newOptions;
                    }
                    renderOptions();
                },
                setValue: (value, text) => {
                    searchInput.value = text || '';
                    hiddenInput.value = value || '';
                },
                clear: () => {
                    searchInput.value = '';
                    hiddenInput.value = '';
                    renderOptions();
                },
                disable: () => {
                    container.classList.add('disabled');
                    searchInput.disabled = true;
                },
                enable: () => {
                    container.classList.remove('disabled');
                    searchInput.disabled = false;
                }
            };
        }
        
        // 初始化搜索选择器
        function initializeSearchableSelects() {
            console.log('开始初始化搜索选择器');
            
            // 省份选择器
            const provinceOptions = [
                {value: '', text: '-- 请选择省份 --'},
                {value: '北京', text: '北京'},
                {value: '天津', text: '天津'},
                {value: '河北', text: '河北'},
                {value: '山西', text: '山西'},
                {value: '内蒙古', text: '内蒙古'},
                {value: '辽宁', text: '辽宁'},
                {value: '吉林', text: '吉林'},
                {value: '黑龙江', text: '黑龙江'},
                {value: '上海', text: '上海'},
                {value: '江苏', text: '江苏'},
                {value: '浙江', text: '浙江'},
                {value: '安徽', text: '安徽'},
                {value: '福建', text: '福建'},
                {value: '江西', text: '江西'},
                {value: '山东', text: '山东'},
                {value: '河南', text: '河南'},
                {value: '湖北', text: '湖北'},
                {value: '湖南', text: '湖南'},
                {value: '广东', text: '广东'},
                {value: '广西', text: '广西'},
                {value: '海南', text: '海南'},
                {value: '重庆', text: '重庆'},
                {value: '四川', text: '四川'},
                {value: '贵州', text: '贵州'},
                {value: '云南', text: '云南'},
                {value: '西藏', text: '西藏'},
                {value: '陕西', text: '陕西'},
                {value: '甘肃', text: '甘肃'},
                {value: '青海', text: '青海'},
                {value: '宁夏', text: '宁夏'},
                {value: '新疆', text: '新疆'}
            ];
            
            window.provinceSelector = createSearchableSelect(
                'provinceSelectContainer',
                'provinceSearch',
                'provinceDropdown',
                'provinceSelect',
                provinceOptions,
                (option) => {
                    updateCitySelect();
                    displayShippingPrice();
                }
            );
            
            // 城市选择器
            window.citySelector = createSearchableSelect(
                'citySelectContainer',
                'citySearch',
                'cityDropdown',
                'citySelect',
                [{value: '', text: '-- 请先选择省份 --'}],
                (option) => {
                    displayShippingPrice();
                }
            );
            
            // 产品选择器
            const productOptions = [{value: '', text: '-- 请选择产品 --'}];
            appData.products.forEach(product => {
                productOptions.push({value: product.id, text: product.name});
            });
            
            window.productSelector = createSearchableSelect(
                'productSelectContainer',
                'productSearch',
                'productDropdown',
                'productSelect',
                productOptions,
                null
            );
        }
        
        // 设置事件监听
        function setupEventListeners() {
            // 菜单切换
            menuToggle.addEventListener('click', function() {
                navMenu.classList.toggle('show');
            });
            
            // 选项卡切换
            navItems.forEach(item => {
                item.addEventListener('click', function() {
                    const tabId = this.getAttribute('data-tab');
                    
                    // 更新导航项状态
                    navItems.forEach(navItem => navItem.classList.remove('active'));
                    this.classList.add('active');
                    
                    // 更新选项卡内容
                    tabContents.forEach(content => content.classList.remove('active'));
                    document.getElementById(tabId).classList.add('active');
                    
                    // 隐藏移动端菜单
                    navMenu.classList.remove('show');
                });
            });
            
            // 价格类型变更
            document.getElementById('priceType').addEventListener('change', function() {
                const unitLabel = document.getElementById('unitLabel').querySelector('div');
                if (this.value === 'weight') {
                    unitLabel.textContent = '元/kg';
                } else {
                    unitLabel.textContent = '元/m³';
                }
            });
            
            // 全省通用选项变更
            document.getElementById('isProvinceWide').addEventListener('change', function() {
                const cityInput = document.getElementById('shippingCity');
                cityInput.disabled = this.checked;
                if (this.checked) {
                    cityInput.value = '';
                }
            });
            
            // 表单提交
            calculatorForm.addEventListener('submit', handleCalculatorSubmit);
            productForm.addEventListener('submit', handleProductSubmit);
            shippingForm.addEventListener('submit', handleShippingSubmit);
            
            // Excel导入导出事件监听器
            document.getElementById('downloadProductTemplate').addEventListener('click', downloadProductTemplate);
            document.getElementById('downloadShippingTemplate').addEventListener('click', downloadShippingTemplate);
            
            // 产品导入按钮点击事件
            document.getElementById('importProductBtn').addEventListener('click', function() {
                document.getElementById('importProductFile').click();
            });
            
            // 产品文件选择事件
            document.getElementById('importProductFile').addEventListener('change', function(e) {
                if (e.target.files.length > 0) {
                    importProductData(e.target.files[0]);
                    // 重置文件输入，允许再次选择相同文件
                    e.target.value = '';
                }
            });
            
            // 运费规则导入按钮点击事件
            document.getElementById('importShippingBtn').addEventListener('click', function() {
                document.getElementById('importShippingFile').click();
            });
            
            // 运费规则文件选择事件
            document.getElementById('importShippingFile').addEventListener('change', function(e) {
                if (e.target.files.length > 0) {
                    importShippingData(e.target.files[0]);
                    // 重置文件输入，允许再次选择相同文件
                    e.target.value = '';
                }
            });
            
            // 添加产品按钮事件监听
            document.getElementById('addProductBtn').addEventListener('click', addProductToSelection);
            
            // 数量加减按钮事件监听（使用事件委托）
            document.addEventListener('click', function(e) {
                if (e.target.classList.contains('quantity-increase')) {
                    const input = e.target.parentElement.querySelector('.sku-quantity');
                    const currentValue = parseInt(input.value) || 0;
                    input.value = currentValue + 1;
                    // 触发input事件以更新计算
                    input.dispatchEvent(new Event('input', { bubbles: true }));
                } else if (e.target.classList.contains('quantity-decrease')) {
                    const input = e.target.parentElement.querySelector('.sku-quantity');
                    const currentValue = parseInt(input.value) || 0;
                    if (currentValue > 0) {
                        input.value = currentValue - 1;
                        // 触发input事件以更新计算
                        input.dispatchEvent(new Event('input', { bubbles: true }));
                    }
                }
            });
        }
        
        // 更新产品下拉框
        function updateProductSelect() {
            console.log('updateProductSelect 被调用');
            console.log('window.productSelector 存在:', !!window.productSelector);
            console.log('appData.products 长度:', appData.products.length);
            console.log('appData.products 内容:', appData.products);
            
            if (window.productSelector) {
                const productOptions = [{value: '', text: '-- 请选择产品 --'}];
                appData.products.forEach(product => {
                    productOptions.push({value: product.id, text: product.name});
                    console.log('添加产品选项:', product.name, 'ID:', product.id);
                });
                console.log('准备更新产品选项，总数:', productOptions.length);
                window.productSelector.updateOptions(productOptions);
                console.log('产品选项更新完成');
            } else {
                console.error('window.productSelector 不存在！');
            }
        }
        
        // 更新省份下拉框
        function updateProvinceSelect() {
            if (window.provinceSelector) {
                // 获取唯一的省份列表
                const provinces = [...new Set(appData.shippingRules.map(rule => rule.province))];
                
                const provinceOptions = [{value: '', text: '-- 请选择省份 --'}];
                provinces.forEach(province => {
                    provinceOptions.push({value: province, text: province});
                });
                
                window.provinceSelector.updateOptions(provinceOptions);
            }
        }
        
        // 更新城市下拉框
        function updateCitySelect() {
            const selectedProvince = document.getElementById('provinceSelect').value;
            
            if (selectedProvince && window.citySelector) {
                // 过滤选定省份的城市
                const cities = appData.shippingRules
                    .filter(rule => rule.province === selectedProvince)
                    .map(rule => rule.city)
                    .filter((city, index, arr) => arr.indexOf(city) === index); // 去重
                
                const cityOptions = [{value: '', text: '-- 请选择城市 --'}];
                cities.forEach(city => {
                    if (city) { // 过滤空城市
                        cityOptions.push({value: city, text: city});
                    }
                });
                
                window.citySelector.setOptions(cityOptions);
                window.citySelector.clear();
                window.citySelector.enable();
            } else if (window.citySelector) {
                window.citySelector.setOptions([{value: '', text: '-- 请先选择省份 --'}]);
                window.citySelector.clear();
                window.citySelector.disable();
            }
        }
        
        // 显示运费单价信息
        function displayShippingPrice() {
            const selectedProvince = document.getElementById('provinceSelect').value;
            const selectedCity = document.getElementById('citySelect').value;
            const shippingDisplay = document.getElementById('shippingPriceDisplay');
            const shippingDetails = document.getElementById('shippingPriceDetails');
            
            if (!selectedProvince) {
                shippingDisplay.style.display = 'none';
                return;
            }
            
            // 查找匹配的运费规则（重量和体积）
            let weightRule = null;
            let volumeRule = null;
            
            if (selectedCity) {
                // 优先查找具体城市的规则
                weightRule = appData.shippingRules.find(rule => 
                    rule.province === selectedProvince && 
                    rule.city === selectedCity && 
                    !rule.isProvinceWide &&
                    rule.priceType === 'weight'
                );
                volumeRule = appData.shippingRules.find(rule => 
                    rule.province === selectedProvince && 
                    rule.city === selectedCity && 
                    !rule.isProvinceWide &&
                    rule.priceType === 'volume'
                );
            }
            
            // 如果没找到具体城市规则，查找全省规则
            if (!weightRule) {
                weightRule = appData.shippingRules.find(rule => 
                    rule.province === selectedProvince && 
                    rule.isProvinceWide &&
                    rule.priceType === 'weight'
                );
            }
            if (!volumeRule) {
                volumeRule = appData.shippingRules.find(rule => 
                    rule.province === selectedProvince && 
                    rule.isProvinceWide &&
                    rule.priceType === 'volume'
                );
            }
            
            if (weightRule || volumeRule) {
                const locationText = selectedCity ? `${selectedProvince} - ${selectedCity}` : `${selectedProvince}（全省）`;
                
                const weightPrice = weightRule ? weightRule.unitPrice : '暂无';
                const volumePrice = volumeRule ? volumeRule.unitPrice : '暂无';
                
                // 同时显示重量和体积两种计费方式
                shippingDetails.innerHTML = `
                    <p><strong>配送地区：</strong>${locationText}</p>
                    <div style="display: flex; gap: 20px; margin-top: 10px;">
                        <div style="flex: 1; padding: 10px; background: #f5f5f5; border-radius: 5px;">
                            <p style="margin: 0; font-weight: bold; color: #2196F3;">按重量计费：</p>
                            <p style="margin: 5px 0 0 0; font-size: 18px; color: #1976D2;">${weightPrice === '暂无' ? '暂无' : '¥' + weightPrice + '/kg'}</p>
                        </div>
                        <div style="flex: 1; padding: 10px; background: #f5f5f5; border-radius: 5px;">
                            <p style="margin: 0; font-weight: bold; color: #4CAF50;">按体积计费：</p>
                            <p style="margin: 5px 0 0 0; font-size: 18px; color: #388E3C;">${volumePrice === '暂无' ? '暂无' : '¥' + volumePrice + '/m³'}</p>
                        </div>
                    </div>
                    <p style="margin-top: 10px; font-size: 12px; color: #666;">
                        <i class="fas fa-info-circle"></i> 运费将根据产品的实际重量和体积分别计算后相加
                    </p>
                `;
                
                shippingDisplay.style.display = 'block';
            } else {
                shippingDetails.innerHTML = `
                    <p><strong>配送地区：</strong>${selectedProvince}${selectedCity ? ` - ${selectedCity}` : ''}</p>
                    <p style="color: #ffeb3b;">⚠️ 暂无该地区的运费规则，请联系客服确认运费</p>
                `;
                
                shippingDisplay.style.display = 'block';
            }
        }
        
        // 获取当前选择的产品信息
        function getSelectedProducts() {
            const selectedProducts = [];
            const productElements = document.querySelectorAll('.selected-product');
            
            productElements.forEach(element => {
                const productId = parseInt(element.dataset.productId);
                const product = appData.products.find(p => p.id === productId);
                
                if (product) {
                    const skuQuantities = [];
                    const skuInputs = element.querySelectorAll('.sku-quantity');
                    
                    skuInputs.forEach(input => {
                        const skuName = input.dataset.skuName;
                        const quantity = parseInt(input.value) || 0;
                        
                        if (quantity > 0) {
                            skuQuantities.push({
                                name: skuName,
                                quantity: quantity
                            });
                        }
                    });
                    
                    if (skuQuantities.length > 0) {
                        selectedProducts.push({
                            product: product,
                            skuQuantities: skuQuantities
                        });
                    }
                }
            });
            
            return selectedProducts;
        }

        
        // 添加产品到选择列表
        function addProductToSelection() {
            const productId = parseInt(document.getElementById('productSelect').value);
            
            if (!productId) {
                alert('请选择一个产品');
                return;
            }
            
            // 检查产品是否已经添加
            if (document.getElementById(`product-${productId}`)) {
                alert('该产品已经添加到列表中');
                return;
            }
            
            const product = appData.products.find(p => p.id === productId);
            
            if (!product) {
                alert('找不到选择的产品');
                return;
            }
            
            const productElement = document.createElement('div');
            productElement.className = 'selected-product';
            productElement.id = `product-${productId}`;
            productElement.dataset.productId = productId;
            
            const productHeader = document.createElement('div');
            productHeader.className = 'product-header';
            
            const productTitle = document.createElement('div');
            productTitle.className = 'product-title';
            productTitle.textContent = product.name;
            
            const removeButton = document.createElement('button');
            removeButton.type = 'button';
            removeButton.className = 'remove-product';
            removeButton.textContent = '移除';
            removeButton.onclick = function() {
                productElement.remove();
            };
            
            productHeader.appendChild(productTitle);
            productHeader.appendChild(removeButton);
            
            const skuTable = document.createElement('div');
            skuTable.className = 'table-responsive';
            skuTable.innerHTML = `
                <table class="sku-table">
                    <thead>
                        <tr>
                            <th>SKU名称</th>
                            <th>单价(元)</th>
                            <th>售价(元)</th>
                            <th>重量(kg)</th>
                            <th>体积(m³)</th>
                            <th>数量</th>
                        </tr>
                    </thead>
                    <tbody>
                        ${product.skus.map(sku => `
                            <tr>
                                <td>${sku.name}</td>
                                <td>${sku.cost}</td>
                                <td>${sku.price || 0}</td>
                                <td>${sku.weight}</td>
                                <td>${sku.volume || 0}</td>
                                <td>
                                    <div class="quantity-input-group">
                                        <button type="button" class="quantity-btn quantity-decrease" data-product-id="${productId}" data-name="${sku.name}">-</button>
                                        <input type="number" class="sku-quantity" data-product-id="${productId}" data-name="${sku.name}" min="0" value="0">
                                        <button type="button" class="quantity-btn quantity-increase" data-product-id="${productId}" data-name="${sku.name}">+</button>
                                    </div>
                                </td>
                            </tr>
                        `).join('')}
                    </tbody>
                </table>
            `;
            
            productElement.appendChild(productHeader);
            productElement.appendChild(skuTable);
            
            document.getElementById('selectedProductsContainer').appendChild(productElement);
            
            // 为SKU数量输入框添加事件监听器，当数量变化时更新运费显示
            productElement.querySelectorAll('.sku-quantity').forEach(input => {
                input.addEventListener('input', function() {
                    // 延迟更新，避免频繁计算
                    clearTimeout(this.updateTimeout);
                    this.updateTimeout = setTimeout(() => {
                        displayShippingPrice();
                    }, 300);
                });
            });
            
            // 重置产品选择下拉框
            if (window.productSelector) {
                window.productSelector.selectOption('');
            }
            
            // 更新运费显示
            displayShippingPrice();
        }
        
        // 处理计算器表单提交
        function handleCalculatorSubmit(e) {
            e.preventDefault();
            
            const province = document.getElementById('provinceSelect').value;
            const city = document.getElementById('citySelect').value;
            const totalSalePrice = parseFloat(totalPrice.value);
            
            if (!province || isNaN(totalSalePrice)) {
                alert('请填写所有必填字段');
                return;
            }
            
            // 获取所有选择的产品和SKU数量
            const selectedProducts = [];
            const productElements = document.querySelectorAll('.selected-product');
            
            if (productElements.length === 0) {
                alert('请至少添加一个产品');
                return;
            }
            
            let hasSelectedSku = false;
            
            productElements.forEach(productElement => {
                const productId = parseInt(productElement.dataset.productId);
                const product = appData.products.find(p => p.id === productId);
                
                if (product) {
                    const skuQuantities = [];
                    productElement.querySelectorAll('.sku-quantity').forEach(input => {
                        const name = input.getAttribute('data-name');
                        const quantity = parseInt(input.value) || 0;
                        
                        if (quantity > 0) {
                            skuQuantities.push({ name, quantity });
                            hasSelectedSku = true;
                        }
                    });
                    
                    if (skuQuantities.length > 0) {
                        selectedProducts.push({
                            product: product,
                            skuQuantities: skuQuantities
                        });
                    }
                }
            });
            
            if (!hasSelectedSku) {
                alert('请至少选择一个SKU并设置数量');
                return;
            }
            
            // 计算利润
            calculateProfit(selectedProducts, province, city, totalSalePrice);
        }
        
        // 计算利润
        function calculateProfit(selectedProducts, province, city, totalSalePrice) {
            // 查找运费规则（重量和体积），优先匹配具体城市，如果没有城市或没有找到具体城市规则则查找全省通用规则
            let weightRule = null;
            let volumeRule = null;
            
            // 如果有城市，先尝试匹配具体城市
            if (city) {
                weightRule = appData.shippingRules.find(r => r.province === province && r.city === city && r.priceType === 'weight');
                volumeRule = appData.shippingRules.find(r => r.province === province && r.city === city && r.priceType === 'volume');
            }
            
            // 如果没有找到具体城市的规则或没有选择城市，查找全省通用规则
            if (!weightRule) {
                weightRule = appData.shippingRules.find(r => r.province === province && r.isProvinceWide && r.priceType === 'weight');
            }
            if (!volumeRule) {
                volumeRule = appData.shippingRules.find(r => r.province === province && r.isProvinceWide && r.priceType === 'volume');
            }
            
            if (!weightRule && !volumeRule) {
                alert('找不到运费规则');
                return;
            }
            
            // 计算货物成本、总重量和总体积
            let totalCost = 0;
            let totalWeight = 0;
            let totalVolume = 0;
            
            // 每个产品的成本明细
            const productDetails = [];
            
            selectedProducts.forEach(item => {
                const product = item.product;
                const skuQuantities = item.skuQuantities;
                
                let productCost = 0;
                let productWeight = 0;
                let productVolume = 0;
                
                skuQuantities.forEach(skuItem => {
                    const sku = product.skus.find(s => s.name === skuItem.name);
                    
                    if (sku) {
                        const skuCost = sku.cost * skuItem.quantity;
                        productCost += skuCost;
                        productWeight += sku.weight * skuItem.quantity;
                        productVolume += (sku.volume || 0) * skuItem.quantity;
                    }
                });
                
                totalCost += productCost;
                totalWeight += productWeight;
                totalVolume += productVolume;
                
                productDetails.push({
                    name: product.name,
                    cost: productCost,
                    weight: productWeight,
                    volume: productVolume
                });
            });
            
            // 根据实际重量和体积分别计算运费
            let weightShippingCost = 0;
            let volumeShippingCost = 0;
            let shippingCost = 0;
            
            if (weightRule && totalWeight > 0) {
                weightShippingCost = totalWeight * weightRule.unitPrice;
            }
            if (volumeRule && totalVolume > 0) {
                volumeShippingCost = totalVolume * volumeRule.unitPrice;
            }
            
            shippingCost = weightShippingCost + volumeShippingCost;
            
            // 计算总成本、毛利润和毛利率
            const totalCostWithShipping = totalCost + shippingCost;  // 总成本 = 运费 + 货物成本
            const grossProfit = totalSalePrice - totalCostWithShipping;  // 毛利润 = 商品总价 - 总成本
            const grossProfitRate = (grossProfit / totalSalePrice) * 100;  // 毛利率 = 毛利润 / 总售价
            
            // 显示结果
            totalCostElement.textContent = `¥${totalCost.toFixed(2)}`;  // 货物成本
            shippingCostElement.textContent = `¥${shippingCost.toFixed(2)}`;  // 运费
            totalCostWithShippingElement.textContent = `¥${totalCostWithShipping.toFixed(2)}`;  // 总成本
            netProfitElement.textContent = `¥${grossProfit.toFixed(2)}`;  // 毛利润
            profitRateElement.textContent = `${grossProfitRate.toFixed(2)}%`;  // 毛利率
            
            // 显示产品明细
            const detailsElement = document.getElementById('productDetails') || document.createElement('div');
            detailsElement.id = 'productDetails';
            detailsElement.className = 'product-details mt-3';
            
            let detailsHTML = '<h3>产品明细</h3><table class="details-table"><thead><tr><th>产品</th><th>成本</th><th>重量</th><th>体积</th></tr></thead><tbody>';
            
            productDetails.forEach(detail => {
                detailsHTML += `
                    <tr>
                        <td>${detail.name}</td>
                        <td>¥${detail.cost.toFixed(2)}</td>
                        <td>${detail.weight.toFixed(2)} kg</td>
                        <td>${detail.volume.toFixed(4)} m³</td>
                    </tr>
                `;
            });
            
            detailsHTML += '</tbody></table>';
            detailsElement.innerHTML = detailsHTML;
            
            // 如果结果卡片下面没有产品明细，则添加
            if (!document.getElementById('productDetails')) {
                document.getElementById('resultCards').after(detailsElement);
            }
            
            resultCards.style.display = 'flex';
            
            // 显示计算过程
            displayCalculationProcess(selectedProducts, productDetails, weightRule, volumeRule, totalCost, totalWeight, totalVolume, weightShippingCost, volumeShippingCost, shippingCost, totalCostWithShipping, grossProfit, grossProfitRate, totalSalePrice);
            
            // 保存计算历史
            appData.calculationHistory.push({
                date: new Date().toISOString(),
                products: selectedProducts.map(item => ({
                    name: item.product.name,
                    skus: item.skuQuantities
                })),
                goodsCost: totalCost,  // 货物成本
                shippingCost,  // 运费
                totalCost: totalCostWithShipping,  // 总成本
                totalSalePrice,  // 总售价
                grossProfit,  // 毛利润
                grossProfitRate  // 毛利率
            });
            
            saveData();
        }
        
        // 显示计算过程
        function displayCalculationProcess(selectedProducts, productDetails, weightRule, volumeRule, goodsCost, totalWeight, totalVolume, weightShippingCost, volumeShippingCost, shippingCost, totalCost, grossProfit, grossProfitRate, totalSalePrice) {
            const processElement = document.getElementById('calculationProcess');
            const contentElement = document.getElementById('processContent');
            
            let processHTML = '<h3>计算过程详情</h3>';
            
            // 1. 产品成本计算
            processHTML += '<div class="process-step">';
            processHTML += '<div class="process-step-title">1. 货物成本计算</div>';
            productDetails.forEach((detail, index) => {
                processHTML += `<div class="process-formula">${detail.name}: ¥${detail.cost.toFixed(2)}</div>`;
            });
            processHTML += `<div class="process-result">货物成本总计 = ¥${goodsCost.toFixed(2)}</div>`;
            processHTML += '</div>';
            
            // 2. 运费计算
            processHTML += '<div class="process-step">';
            processHTML += '<div class="process-step-title">2. 运费计算</div>';
            
            // 按重量计费
            if (weightRule && totalWeight > 0) {
                processHTML += `<div class="process-formula">按重量计费: ${totalWeight.toFixed(2)} kg × ¥${weightRule.unitPrice}/kg = ¥${weightShippingCost.toFixed(2)}</div>`;
            } else if (weightRule) {
                processHTML += `<div class="process-formula">按重量计费: ${totalWeight.toFixed(2)} kg × ¥${weightRule.unitPrice}/kg = ¥0.00 (无重量)</div>`;
            }
            
            // 按体积计费
            if (volumeRule && totalVolume > 0) {
                processHTML += `<div class="process-formula">按体积计费: ${totalVolume.toFixed(4)} m³ × ¥${volumeRule.unitPrice}/m³ = ¥${volumeShippingCost.toFixed(2)}</div>`;
            } else if (volumeRule) {
                processHTML += `<div class="process-formula">按体积计费: ${totalVolume.toFixed(4)} m³ × ¥${volumeRule.unitPrice}/m³ = ¥0.00 (无体积)</div>`;
            }
            
            // 总运费
            if (weightRule && volumeRule) {
                processHTML += `<div class="process-formula">总运费 = 重量运费 + 体积运费 = ¥${weightShippingCost.toFixed(2)} + ¥${volumeShippingCost.toFixed(2)}</div>`;
            }
            processHTML += `<div class="process-result">运费 = ¥${shippingCost.toFixed(2)}</div>`;
            processHTML += '</div>';
            
            // 3. 总成本计算
            processHTML += '<div class="process-step">';
            processHTML += '<div class="process-step-title">3. 总成本计算</div>';
            processHTML += `<div class="process-formula">总成本 = 货物成本 + 运费</div>`;
            processHTML += `<div class="process-formula">总成本 = ¥${goodsCost.toFixed(2)} + ¥${shippingCost.toFixed(2)}</div>`;
            processHTML += `<div class="process-result">总成本 = ¥${totalCost.toFixed(2)}</div>`;
            processHTML += '</div>';
            
            // 4. 毛利润计算
            processHTML += '<div class="process-step">';
            processHTML += '<div class="process-step-title">4. 毛利润计算</div>';
            processHTML += `<div class="process-formula">毛利润 = 总售价 - 总成本</div>`;
            processHTML += `<div class="process-formula">毛利润 = ¥${totalSalePrice.toFixed(2)} - ¥${totalCost.toFixed(2)}</div>`;
            processHTML += `<div class="process-result">毛利润 = ¥${grossProfit.toFixed(2)}</div>`;
            processHTML += '</div>';
            
            // 5. 毛利率计算
            processHTML += '<div class="process-step">';
            processHTML += '<div class="process-step-title">5. 毛利率计算</div>';
            processHTML += `<div class="process-formula">毛利率 = (毛利润 ÷ 总售价) × 100%</div>`;
            processHTML += `<div class="process-formula">毛利率 = (¥${grossProfit.toFixed(2)} ÷ ¥${totalSalePrice.toFixed(2)}) × 100%</div>`;
            processHTML += `<div class="process-result">毛利率 = ${grossProfitRate.toFixed(2)}%</div>`;
            processHTML += '</div>';
            

            
            contentElement.innerHTML = processHTML;
            processElement.style.display = 'block';
        }
        

        
        // 处理产品表单提交
        function handleProductSubmit(e) {
            e.preventDefault();
            
            const productName = document.getElementById('productName').value.trim();
            
            if (!productName) {
                alert('请输入产品名称');
                return;
            }
            
            // 生成新的产品ID
            const newId = appData.products.length > 0 
                ? Math.max(...appData.products.map(p => p.id)) + 1 
                : 1;
            
            // 添加新产品
            appData.products.push({
                id: newId,
                name: productName,
                skus: []
            });
            
            // 保存数据并更新UI
            saveData();
            updateProductSelect();
            renderProductList();
            
            // 重置表单
            document.getElementById('productName').value = '';
        }
        
        // 处理运费规则表单提交
        function handleShippingSubmit(e) {
            e.preventDefault();
            
            const province = document.getElementById('shippingProvince').value.trim();
            const isProvinceWide = document.getElementById('isProvinceWide').checked;
            let city = document.getElementById('shippingCity').value.trim();
            const priceType = document.getElementById('priceType').value;
            const unitPrice = parseFloat(document.getElementById('unitPrice').value);
            
            if (!province || isNaN(unitPrice) || unitPrice <= 0) {
                alert('请填写所有必填字段');
                return;
            }
            
            // 如果是全省通用，则城市设为空
            if (isProvinceWide) {
                city = '';
            } else if (!city) {
                alert('请选择城市或勾选全省通用');
                return;
            }
            
            // 检查是否已存在相同省市的规则
            const existingRuleIndex = appData.shippingRules.findIndex(
                r => r.province === province && (isProvinceWide ? r.isProvinceWide : r.city === city)
            );
            
            if (existingRuleIndex !== -1) {
                // 更新现有规则
                appData.shippingRules[existingRuleIndex] = {
                    province, city, priceType, unitPrice, isProvinceWide
                };
            } else {
                // 添加新规则
                appData.shippingRules.push({
                    province, city, priceType, unitPrice, isProvinceWide
                });
            }
            
            // 保存数据并更新UI
            saveData();
            updateProvinceSelect();
            renderShippingRules();
            
            // 重置表单
            document.getElementById('shippingProvince').value = '';
            document.getElementById('shippingCity').value = '';
            document.getElementById('unitPrice').value = '';
            document.getElementById('isProvinceWide').checked = false;
        }
        
        // 渲染产品列表
        function renderProductList() {
            productList.innerHTML = '';
            
            appData.products.forEach(product => {
                const productElement = document.createElement('div');
                productElement.className = 'card mb-3';
                
                // 产品信息和操作按钮
                const productHeader = document.createElement('div');
                productHeader.className = 'form-group inline';
                productHeader.innerHTML = `
                    <div style="flex: 2;">
                        <h3>${product.name}</h3>
                    </div>
                    <div style="flex: 1; text-align: right;">
                        <button type="button" class="danger delete-product" data-id="${product.id}">删除</button>
                    </div>
                `;
                
                productElement.appendChild(productHeader);
                
                // 克隆SKU管理模板
                const template = document.getElementById('skuManagementTemplate');
                const skuManagement = template.content.cloneNode(true);
                
                // 设置SKU表单提交事件
                const skuForm = skuManagement.querySelector('.sku-form');
                skuForm.addEventListener('submit', function(e) {
                    e.preventDefault();
                    
                    const skuName = this.querySelector('.sku-name').value.trim();
                    const skuCost = parseFloat(this.querySelector('.sku-cost').value);
                    const skuPrice = parseFloat(this.querySelector('.sku-price').value);
                    const skuWeight = parseFloat(this.querySelector('.sku-weight').value);
                    const skuVolume = parseFloat(this.querySelector('.sku-volume').value);
                    
                    if (!skuName || isNaN(skuCost) || isNaN(skuPrice) || isNaN(skuWeight) || isNaN(skuVolume)) {
                        alert('请填写所有SKU字段');
                        return;
                    }
                    
                    // 添加新SKU
                    product.skus.push({
                        name: skuName,
                        cost: skuCost,
                        price: skuPrice,
                        weight: skuWeight,
                        volume: skuVolume
                    });
                    
                    // 保存数据并更新UI
                    saveData();
                    renderProductList();
                    updateSkuTable();
                });
                
                // 渲染SKU列表
                const skuListTable = skuManagement.querySelector('.sku-list-table tbody');
                
                product.skus.forEach((sku, index) => {
                    const row = document.createElement('tr');
                    row.innerHTML = `
                        <td>${sku.name}</td>
                        <td>${sku.cost}</td>
                        <td>${sku.price || 0}</td>
                        <td>${sku.weight}</td>
                        <td>${sku.volume || 0}</td>
                        <td>
                            <button type="button" class="danger delete-sku" 
                                data-product-id="${product.id}" 
                                data-sku-index="${index}">
                                删除
                            </button>
                        </td>
                    `;
                    skuListTable.appendChild(row);
                });
                
                productElement.appendChild(skuManagement);
                productList.appendChild(productElement);
            });
            
            // 添加删除产品事件监听
            document.querySelectorAll('.delete-product').forEach(button => {
                button.addEventListener('click', function() {
                    const productId = parseInt(this.getAttribute('data-id'));
                    
                    if (confirm('确定要删除此产品吗？')) {
                        appData.products = appData.products.filter(p => p.id !== productId);
                        saveData();
                        updateProductSelect();
                        renderProductList();
                    }
                });
            });
            
            // 添加删除SKU事件监听
            document.querySelectorAll('.delete-sku').forEach(button => {
                button.addEventListener('click', function() {
                    const productId = parseInt(this.getAttribute('data-product-id'));
                    const skuIndex = parseInt(this.getAttribute('data-sku-index'));
                    
                    if (confirm('确定要删除此SKU吗？')) {
                        const product = appData.products.find(p => p.id === productId);
                        
                        if (product) {
                            product.skus.splice(skuIndex, 1);
                            saveData();
                            renderProductList();
                            updateSkuTable();
                        }
                    }
                });
            });
        }
        
        // 渲染运费规则
        function renderShippingRules() {
            shippingRulesBody.innerHTML = '';
            
            appData.shippingRules.forEach((rule, index) => {
                const row = document.createElement('tr');
                
                // 显示城市或全省通用
                const cityDisplay = rule.isProvinceWide ? '全省通用' : rule.city;
                
                // 显示计价方式和单价
                const priceTypeDisplay = rule.priceType === 'weight' ? '按重量' : '按体积';
                const unitDisplay = rule.priceType === 'weight' ? '元/kg' : '元/m³';
                
                row.innerHTML = `
                    <td>${rule.province}</td>
                    <td>${cityDisplay}</td>
                    <td>${priceTypeDisplay}</td>
                    <td>${rule.unitPrice} ${unitDisplay}</td>
                    <td>
                        <button type="button" class="danger delete-rule" data-index="${index}">删除</button>
                    </td>
                `;
                
                shippingRulesBody.appendChild(row);
            });
            
            // 添加删除规则事件监听
            document.querySelectorAll('.delete-rule').forEach(button => {
                button.addEventListener('click', function() {
                    const index = parseInt(this.getAttribute('data-index'));
                    
                    if (confirm('确定要删除此运费规则吗？')) {
                        appData.shippingRules.splice(index, 1);
                        saveData();
                        updateProvinceSelect();
                        renderShippingRules();
                    }
                });
            });
        }
        

    </script>
</body>
</html>